<?php

namespace App\Console\Commands\Shop;

use App\Models\ChatGroup\ChatGroupHistoryModel;
use App\Models\ChatGroup\ChatGroupModel;
use App\Models\ChatGroup\ChatGroupSessionAppraiseModel;
use App\Models\ChatGroup\ChatGroupSessionModel;
use App\Models\ChatGroup\ChatGroupUserModel;
use App\Models\Common\ConfigModel;
use App\Models\Shop\ShopModel;
use App\Service\ChatGroup\ChatGroupService;
use Illuminate\Console\Command;

class InitShopGroupCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shop:init_shop_group';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化门店群聊';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $shopIds = json_decode(ConfigModel::getValue('chatGroup', 'betaShopIds'), true);

        ShopModel::query()
                 ->when($shopIds, function ($query) use ($shopIds) {
                     $query->whereIn('id', $shopIds);
                 })
                 ->where('status', '!=', ShopModel::STATUS_CLOSE)
                 ->get()
                 ->each(function (ShopModel $shop) {
                     ChatGroupService::initGroup($shop->id, ChatGroupModel::TYPE_CUSTOMER_SERVE, true);

                     dump($shop->id);
                 });
    }

}
